/**
 * WADLinkDialog - Dialog for configure properties of each CaseLink object
 */
package wads.app;

import java.awt.Frame;
import java.awt.GridLayout;
import wads.drawing.line.WADLink;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import wads.drawing.line.CaseLink;


public class WADLinkDialog extends CaseLinkDialog {
  /**
   * @serial -2992115782708102731
   */
  
  public static final int CONDITION_TYPE_NONE = 0;
  public static final int CONDITION_TYPE_CONDITION = 1;
  public static final int CONDITION_TYPE_OTHERWISE = 2;
  public static final int CONDITION_TYPE_EXCEPTION = 3;
  public static final int CONDITION_TYPE_DEFAULTEXCEPTION = 4;
//  private Vector<String> ConditionType = new Vector<String>();
  private String[] ConditionTypes = {"None", "Condition", "Otherwise", "Exception", "Default Exception"};

  private JComboBox ConditionTypeComboBox;
  private JTextField ConditionTextField;
  private String ConditionExpression;
  private WADLink link;
  
  /**
   * @param parent Dialog's parent frame.
   * @param owner CaseLink object dialog owner.
   */
  public WADLinkDialog(Frame parent, CaseLink owner) {
    super(parent, owner);
    this.link = (WADLink)owner;
    this.setTitle("Link Properties Setting");
    
    try {
      jbInit();
    }
    catch(Exception e) {
      System.out.println("Exception thrown from WADLinkDialog constructor while call jbInit() method.");
      e.printStackTrace();
    }
  }
  
  private void jbInit() throws Exception {
    JPanel CTCBWrapperPanel = new JPanel();
    CTCBWrapperPanel.setLayout(new GridLayout(2, 1));
    JLabel CondTypeLabel = new JLabel("Choose condition type");
    ConditionTypeComboBox = new JComboBox(ConditionTypes);
    CTCBWrapperPanel.add(CondTypeLabel);
    CTCBWrapperPanel.add(ConditionTypeComboBox);
    
    JPanel CTFWrapperPanel = new JPanel();
    CTFWrapperPanel.setLayout(new GridLayout(2, 1));
    JLabel ConditionLabel = new JLabel("Condition Expression");
    ConditionTextField = new JTextField();
    CTFWrapperPanel.add(ConditionLabel);
    CTFWrapperPanel.add(ConditionTextField);
    
    this.addControl(CTCBWrapperPanel);
    this.addControl(CTFWrapperPanel);
    
    setSize(400, 300);
  }
  
  @Override
  public void OKButton_actionPerformed(ActionEvent e) {
//    ((WADLink)this.getLink()).setLinkProperties(WADLink.LINK_CONDITION_TYPE_KEYNAME, ConditionTypeComboBox.getSelectedItem().toString());
    this.getLink().setConditionType(ConditionTypeComboBox.getSelectedItem().toString());
//    ((WADLink)this.getLink()).setLinkProperties(WADLink.LINK_CONDITION_EXPRESSION_KEYNAME, ConditionTextField.getText());
    this.getLink().setConditionExpression(ConditionTextField.getText());
    this.dispose();
  }
  
  @Override
  public void CancelButton_actionPerformed(ActionEvent e) {
    this.dispose();
  }

  /**
   * @return the Vector that contains Condition Types.
   */
  public String[] getConditionTypes() {
    return ConditionTypes;
  }

  /**
   * @return the Link's Condition.
   */
  public String getConditionExpression() {
    return ConditionExpression;
  }

  /**
   * @param conditionPCDATA Set Condition to each link.
   */
  public void setConditionExpression(String conditionPCDATA) {
    ConditionExpression = conditionPCDATA;
  }

    /**
     * @return the link
     */
    public WADLink getLink() {
        return link;
    }

    /**
     * @param link the link to set
     */
    public void setLink(WADLink link) {
        this.link = link;
    }
}
